package com.education.welco.service.impl;

import com.education.common.utils.Convert;
import com.education.welco.mapper.SReportMapper;
import com.education.welco.pojo.SReport;
import com.education.welco.pojo.SReportInfo;
import com.education.welco.service.ISReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 举报 服务层实现
 *
 * @author d
 * @date 2022-06-25
 */
@Service
public class SReportServiceImpl implements ISReportService {

    @Autowired
    private SReportMapper sReportMapper;

    /**
     * 查询举报信息
     *
     * @param cReportId 举报ID
     * @return 举报信息
     */
    @Override
    public SReport selectSReportById(String cReportId) {
        return sReportMapper.selectSReportById(cReportId);
    }

    /**
     * 查询举报列表
     *
     * @param sReport 举报信息
     * @return 举报集合
     */
    @Override
    public List<SReport> selectSReportList(SReport sReport) {
        //s_report s_answering_comment
        List<SReport> sReports1 = sReportMapper.selectSReportList(sReport);
        //s_report educationplam.jr_comments_live
        List<SReport> sReports2 = sReportMapper.selectSReportList1(sReport);
        sReports1.addAll(sReports2);
        return sReports1;
    }

    /**
     * 新增举报
     *
     * @param sReport 举报信息
     * @return 结果
     */
    @Override
    public int insertSReport(SReport sReport) {
        return sReportMapper.insertSReport(sReport);
    }

    /**
     * 修改举报
     *
     * @param sReport 举报信息
     * @return 结果
     */
    @Override
    public int updateSReport(SReport sReport) {
        return sReportMapper.updateSReport(sReport);
    }

    /**
     * 删除举报对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteSReportByIds(String ids) {
        return sReportMapper.deleteSReportByIds(Convert.toStrArray(ids));
    }

    /**
     * 新增(举报)
     *
     * @param map (论坛举报)信息
     * @return 结果
     */
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    @Override
    public int insertSysForumsReport(Map<String, Object> map) {
        String userID = (String) map.get("userID");
        String userName = (String) map.get("userName");
        String userIco = (String) map.get("userIco");
        String cKeyId = (String) map.get("cKeyId");
        String cReportType = (String) map.get("cReportType");
        String cReportRsn = (String) map.get("cReportRsn");
        String cKeyContent = (String) map.get("cKeyContent");

        SReport sReport = new SReport();
        sReport.setCKeyId(cKeyId);
        sReport.setcKeyContent(cKeyContent);
        sReport.setCReportTitle(cReportRsn);
        sReport.setCReportType(cReportType);
        sReport.setCText5("1");
        sReport.setCCreateBy(userName);
        sReport.setTCreateTime(new Date());
        sReportMapper.insertSysForumsReport(sReport);
        String reportId = sReport.getCReportId();

        // 保存明细信息
        SReportInfo sReportInfo = new SReportInfo();
        sReportInfo.setCReportId(reportId);
        sReportInfo.setCUserIco(userIco);
        sReportInfo.setCUserName(userName);
        sReportInfo.setCUserId(userID);
        sReportInfo.setCReportRsn(cReportRsn);
        sReportInfo.setNReportResult(2);
        sReportInfo.setCCreateBy(userName);
        sReportInfo.setTCreateTime(new Date());
        return sReportMapper.insertSysForumsReportInfo(sReportInfo);
    }

    @Override
    public List<SReport> selectSReportListForComment(SReport sReport) {
        List<SReport> sReports1 = sReportMapper.selectSReportList(sReport);
        return sReports1;
    }
}